package com.wuxiaofan.secondkill.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaofan.secondkill.client.Idgenerator;
import com.wuxiaofan.secondkill.entity.SeckillGoods;
import com.wuxiaofan.secondkill.entity.custom.SeckillGoodsCustom;
import com.wuxiaofan.secondkill.entity.vo.GoodsVO;
import com.wuxiaofan.secondkill.mapper.SeckillGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class SeckillGoodsService {
    @Autowired
    private SeckillGoodsMapper SeckillGoodsMapper;
    @Resource
    private Idgenerator idgenerator;

    public GoodsVO findById(String id) {
        return SeckillGoodsMapper.findVoById(id);
    }

    public SeckillGoodsCustom findCountByMap(Map paraMap) {
        return SeckillGoodsMapper.findCountByMap(paraMap);
    }

    public SeckillGoodsCustom findGroupByMap(Map paraMap) {
        return SeckillGoodsMapper.findGroupByMap(paraMap);
    }

    public List<GoodsVO> findByMap(Map paraMap) {
        return SeckillGoodsMapper.findByMap(paraMap);
    }

    public Page<GoodsVO> findByMap(Map paraMap, Page page) {
        return page.setRecords(SeckillGoodsMapper.findByMap(paraMap, page));
    }


    public void updateMapById(Map paraMap) {
        SeckillGoodsMapper.updateMapById(paraMap);
    }

    public void delById(String id) {
        SeckillGoodsMapper.deleteById(id);
    }

    public SeckillGoods save(SeckillGoods SeckillGoods) {
        SeckillGoods.setId(idgenerator.getId());
        SeckillGoodsMapper.insert(SeckillGoods);
        return SeckillGoods;
    }

}
